const express = require("express");
let app = express();

const param = JSON.parse(process.argv[2]);
const { prefix, dir, files } = param;

app.use("/video", express.static(dir));

app.get("/list", async (req, res) => {
  let list = files.map((n) => {
    let src = `${prefix}/video/${n}`;
    return `<div><a href=${src}>${n}</a></div>`;
  });
  let html = `<html>
        <head>
            <meta charset="UTF-8" />
        </head>
        ${list.join("")}
    </html>`;
  res.end(html);
});

app.get("/test", async (req, res) => {
  res.json({ name: files });
});

app.listen(3000, () => {
  console.log("web start");
});
